<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>自定义过滤器</title>
	<script src="js/vue.js"></script>
	<script>
		/**
		 * 自定义过滤器
		 */
		//为个位数补0
		Vue.filter('addZero',function(data){
			// console.log(data);
			return data<10?'0'+data:data;
		});

		//双向过滤器
		Vue.filter('currencyDisplay',{
			read:function(data){ //模型--->视图
				// console.log(111);	
				return '$'+data.toFixed(3);
			},
			write:function(newValue,oldValue){ //视图--->模型
				// console.log(222);
				 console.log(oldValue);
				 console.log(newValue);
				return +newValue.replace(/[^\d.]/g,'');
			}
		});

		window.onload=function(){
			var vm=new Vue({
				el:'#itany',
				data:{ 
					currentTime:Date.now(),
					money:12.345
				}
			});
		};
	</script>
</head>
<body>
	<div id="itany">	
		<h3>{{8 | addZero}}</h3>

		<!-- 双向过滤器 -->
		<input type="text" v-model="money | currencyDisplay">
		<h3>{{money | currencyDisplay}}</h3>
		<h3>{{money}}</h3>

	</div>
</body>
</html>